package fun.sboy.headacheMemo.util;

import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;

public class RequestContextHolderUtil {

    /**
     * 获取当前request用户ID
     *
     * @return
     */
    public static String getCurrentUserId() {
        String uid = (String) RequestContextHolder.currentRequestAttributes().getAttribute("currentUser", RequestAttributes.SCOPE_REQUEST);
        if (uid == null) {
            throw new RuntimeException("当前还未登录，请先登录！");
        }
        return uid;
    }
}
